import QtQuick
import QtQuick.Window
import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Controls.Basic

HWindow {
    id: root
    width: 1080
    height: 800
    visible: true
    Rectangle {
        id: c1
        width: 60
        height: parent.height
        MainPanel {
            anchors.fill: parent
            onWPositionChanged: (x, y) => {
                                    root.setX(root.x + x)
                                    root.setY(root.y + y)
                                }

            onPageIndexChanged: index => {
                                    level2Panel.indexChanged(index)
                                }
        }
    }

    SplitView {
        anchors.left: c1.right
        anchors.bottom: root.bottom
        anchors.right: root.right
        anchors.topMargin: root.height - barHeight
        width: root.width - 57
        height: root.height

        handle: Rectangle {
            implicitWidth: 1
            implicitHeight: 1
            color: '#d5d5d5'
        }

        Rectangle {
            SplitView.minimumWidth: 200 //在SplitView中最小宽度
            SplitView.preferredWidth: 300 //item 默认显示宽度，范围在minimun和maximum之间，默认未设置，会使用item的implicitWidth(隐式宽度)
            SplitView.maximumWidth: 650 //在SplitView中最大宽度
            implicitWidth: 270
            color: '#f7f7f7'
            Level2Panel {
                id: level2Panel
                width: parent.width
                height: parent.height
                property var currentChatObj: null
                onOpenChat: (title, sn) => {
                                if (currentChatObj) {
                                    currentChatObj.destroy()
                                    currentChatObj = null
                                }
                                var com = Qt.createComponent('Level3Panel.qml')
                                if (com.status === Component.Ready) {
                                    currentChatObj = com.createObject(p3C, {
                                                                          "title": title,
                                                                          "sn": sn,
                                                                          "enableInfo": true
                                                                      })
                                    currentChatObj.anchors.fill = p3C
                                }
                            }
            }
        }

        Rectangle {
            y: root.height - barHeight
            color: '#ececec'
            HTitleBar {
                id: titleBar
                anchors.top: parent.top
                anchors.right: parent.right
                width: 3 * (root.barHeight + 10)
                height: root.barHeight
                onWWindowsMinimizedCmd: {
                    root.showMinimized()
                }
                onWWindowsMaximizedCmd: {
                    if (root.visibility === Window.Maximized) {
                        root.showNormal()
                    } else {
                        root.showMaximized()
                    }
                }
                onWWindowsCloseedCmd: {
                    root.close()
                }
            }

            Rectangle {
                id: p3C
                y: barHeight
                width: parent.width
                height: root.height - titleBar.height
                color: '#ececec'
                Image {
                    anchors.centerIn: parent
                    source:"qrc:/img/icon/微信.png"
                    width:100
                    height:100
                }
            }
        }
    }
}
